<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js教程," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="1、JS对于字符串的切割截取1.1 函数：split()功能：使用一个指定的分隔符把一个字符串分割存储到数组例子：123 str=”jpg|bmp|gif|ico|png”; arr=str.split(”|”);//arr是一个包含字符值”jpg”、”bmp”、”gif”、”ico”和”png”的数组 1.2 函数：join()功能：使用您选择的分隔符将一个数组合并为一个字符串 例子： 1234">
<meta name="keywords" content="js教程">
<meta property="og:type" content="article">
<meta property="og:title" content="js常用方法，">
<meta property="og:url" content="http://yoursite.com/2018/10/24/js常用方法/index.html">
<meta property="og:site_name" content="沙漠的勇者">
<meta property="og:description" content="1、JS对于字符串的切割截取1.1 函数：split()功能：使用一个指定的分隔符把一个字符串分割存储到数组例子：123 str=”jpg|bmp|gif|ico|png”; arr=str.split(”|”);//arr是一个包含字符值”jpg”、”bmp”、”gif”、”ico”和”png”的数组 1.2 函数：join()功能：使用您选择的分隔符将一个数组合并为一个字符串 例子： 1234">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-10-24T07:31:50.516Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js常用方法，">
<meta name="twitter:description" content="1、JS对于字符串的切割截取1.1 函数：split()功能：使用一个指定的分隔符把一个字符串分割存储到数组例子：123 str=”jpg|bmp|gif|ico|png”; arr=str.split(”|”);//arr是一个包含字符值”jpg”、”bmp”、”gif”、”ico”和”png”的数组 1.2 函数：join()功能：使用您选择的分隔符将一个数组合并为一个字符串 例子： 1234">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/10/24/js常用方法/"/>





  <title>js常用方法， | 沙漠的勇者</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband">
    <a href="https://github.com/" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#fff; color:#151513; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    </div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">沙漠的勇者</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/2018/10/24/js常用方法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="xz_strive">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="沙漠的勇者">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">js常用方法，</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-24T15:09:20+08:00">
                2018-10-24
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="1、JS对于字符串的切割截取"><a href="#1、JS对于字符串的切割截取" class="headerlink" title="1、JS对于字符串的切割截取"></a>1、JS对于字符串的切割截取</h1><h2 id="1-1-函数：split"><a href="#1-1-函数：split" class="headerlink" title="1.1 函数：split()"></a>1.1 函数：split()</h2><p>功能：使用一个指定的分隔符把一个字符串分割存储到数组<br>例子：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> str=”jpg|bmp|gif|ico|png”; arr=str.split(”|”);</span><br><span class="line"></span><br><span class="line">//arr是一个包含字符值”jpg”、”bmp”、”gif”、”ico”和”png”的数组</span><br></pre></td></tr></table></figure></p>
<h2 id="1-2-函数：join"><a href="#1-2-函数：join" class="headerlink" title="1.2 函数：join()"></a>1.2 函数：join()</h2><p>功能：使用您选择的分隔符将一个数组合并为一个字符串</p>
<p>例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">var delimitedString=myArray.join(delimiter);</span><br><span class="line"></span><br><span class="line">var myList=new Array(”jpg”,”bmp”,”gif”,”ico”,”png”);</span><br><span class="line"></span><br><span class="line">var portableList=myList.join(”|”);</span><br><span class="line"></span><br><span class="line">//结果是jpg|bmp|gif|ico|png</span><br></pre></td></tr></table></figure>
<h2 id="1-3-函数-concat（）"><a href="#1-3-函数-concat（）" class="headerlink" title="1.3 函数:concat（）"></a>1.3 函数:concat（）</h2><p>功能：将两个数组连接在一起；</p>
<p>例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">arr1=[1,2,3,4]</span><br><span class="line"></span><br><span class="line">　　arr2=[5,6,7,8]</span><br><span class="line"></span><br><span class="line">　　alert(arr1.concat(arr2))  //结果为[1,2,3,4,5,6,7,8]</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h2 id="1-4-函数-charAt"><a href="#1-4-函数-charAt" class="headerlink" title="1.4 函数:charAt()"></a>1.4 函数:charAt()</h2><p>功能：返回指定位置的字符。字符串中第一个字符的下标是 0。如果参数 index 不在 0 与 string.length 之间，该方法将返回一个空字符串。</p>
<p>例子:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var str=&apos;a,g,i,d,o,v,w,d,k,p&apos;</span><br><span class="line"></span><br><span class="line">alert(str.charAt(2))  //结果为g</span><br></pre></td></tr></table></figure>
<h2 id="1-5-函数-charCodeAt"><a href="#1-5-函数-charCodeAt" class="headerlink" title="1.5 函数:charCodeAt()"></a>1.5 函数:charCodeAt()</h2><p>功能：charCodeAt() 方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。</p>
<p>方法 charCodeAt() 与 charAt() 方法执行的操作相似，只不过前者返回的是位于指定位置的字符的编码，而后者返回的是字符子串。</p>
<p>例子：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var str=&apos;a,g,i,d,o,v,w,d,k,p&apos;</span><br><span class="line"></span><br><span class="line">alert(str.charCodeAt(2))  //结果为103。即g的Unicode编码为103</span><br></pre></td></tr></table></figure></p>
<h2 id="1-6-函数-slice"><a href="#1-6-函数-slice" class="headerlink" title="1.6 函数:slice()"></a>1.6 函数:slice()</h2><p>功能：arrayObject.slice(start,end)</p>
<p>　　start:必需。规定从何处开始选取。如果是负数，那么它规定从数组尾部开始算起的位置。也就是说，-1 指最后一个元素，-2 指倒数第二个元素，以此类推。</p>
<p>　　end:可选。规定从何处结束选取。该参数是数组片断结束处的数组下标。如果没有指定该参数，那么切分的数组包含从 start 到数组结束的所有元素。如果这个参数是负数，那么它规定的是从数组尾部开始算起的元素。</p>
<p>　　返回一个新的数组，包含从start到end（不包括该元素）的arrayobject中的元素。</p>
<p>例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var str=&apos;ahji3o3s4e6p8a0sdewqdasj&apos;</span><br><span class="line"></span><br><span class="line">　　alert(str.slice(2,5))   //结果ji3</span><br></pre></td></tr></table></figure>
<h2 id="1-7函数-substring"><a href="#1-7函数-substring" class="headerlink" title="1.7函数:substring()"></a>1.7函数:substring()</h2><p>定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符。</p>
<p>语法 stringObject.substring(start,stop)</p>
<p> start 必需。一个非负的整数，规定要提取的子串的第一个字符在 stringObject 中的位置。</p>
<p>stop 可选。一个非负的整数，比要提取的子串的最后一个字符在 stringObject 中的位置多 1。</p>
<p>如果省略该参数，那么返回的子串会一直到字符串的结尾。</p>
<p>返回 一个新的字符串，该字符串值包含 stringObject 的一个子字符串，其内容是从 start 处到 stop-1 处的所有字符，其长度为 stop 减 start。 说明 substring 方法返回的子串包括 start 处的字符，但不包括 end 处的字符。 如果 start 与 end 相等，那么该方法返回的就是一个空串（即长度为 0 的字符串）。 如果 start 比 end 大，那么该方法在提取子串之前会先交换这两个参数。 如果 start 或 end 为负数，那么它将被替换为 0。</p>
<p>例子:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var str=&apos;ahji3o3s4e6p8a0sdewqdasj&apos;</span><br><span class="line"></span><br><span class="line">alert(str.substring(2,6))   //结果为ji3o3</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    
    <div>
      
      <div>

    <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>

</div>
      
    </div>
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/js教程/" rel="tag"><i class="fa fa-tag"></i> js教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/10/15/vue引用jquery/" rel="next" title="vue引用jquery">
                <i class="fa fa-chevron-left"></i> vue引用jquery
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/10/24/vue路由监听/" rel="prev" title="vue路由监听">
                vue路由监听 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.gif"
               alt="xz_strive" />
          <p class="site-author-name" itemprop="name">xz_strive</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1、JS对于字符串的切割截取"><span class="nav-number">1.</span> <span class="nav-text">1、JS对于字符串的切割截取</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-函数：split"><span class="nav-number">1.1.</span> <span class="nav-text">1.1 函数：split()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-函数：join"><span class="nav-number">1.2.</span> <span class="nav-text">1.2 函数：join()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-函数-concat（）"><span class="nav-number">1.3.</span> <span class="nav-text">1.3 函数:concat（）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-4-函数-charAt"><span class="nav-number">1.4.</span> <span class="nav-text">1.4 函数:charAt()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-5-函数-charCodeAt"><span class="nav-number">1.5.</span> <span class="nav-text">1.5 函数:charCodeAt()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-6-函数-slice"><span class="nav-number">1.6.</span> <span class="nav-text">1.6 函数:slice()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-7函数-substring"><span class="nav-number">1.7.</span> <span class="nav-text">1.7函数:substring()</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xz_strive</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  









  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/blog/lib/three/three.min.js"></script>

  
  <script type="text/javascript" src="/blog/lib/three/three-waves.min.js"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  





  

  

  

  

  

  

</body>
</html>
<!-- 页面点击小红心 --> 
<script type="text/javascript" src="/js/src/love.js"></script>
